package logic

import (
	"context"
	"good_srv/goodclient"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type OrderPayLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewOrderPayLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderPayLogic {
	return &OrderPayLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *OrderPayLogic) OrderPay(req *types.OrderPayRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	info, err := l.svcCtx.Good.OrderPay(l.ctx, &goodclient.OrderPayRequest{
		UserId:  req.UserId,
		GoodId:  req.GoodId,
		Num:     req.Num,
		PayType: req.PayType,
		Status:  req.Status,
		Times:   req.Times,
	})
	if err != nil {
		return &types.Response{
			Code: 500,
			Msg:  err.Error(),
			Data: nil,
		}, nil
	}
	return &types.Response{
		Code: 200,
		Msg:  "订单支付成功",
		Data: info,
	}, nil
}
